﻿
using Prism.Ioc;
using Prism.Modularity;
using Prism.Regions;
using Prism.Unity;
using PrismDemo.Commons.Util;
using PrismDemo.ViewModels;
using PrismDemo.Views;
using PdfModule;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Prism.Services.Dialogs;

namespace PrismDemo
{
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            //ViewModelLocationProvider.Register注册程序主页面
            return Container.Resolve<MainWindow>();
        }
        //【2】注册页面
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //向容器中注入导航页面，注册时可以指定ViewMode并指定别名，省略的话会自动查找VM，名称默认TView
            //RegisterForNavigation<TView,TViewModel>("别名")
            containerRegistry.RegisterForNavigation<ChartTest>();
            //第一个参数是View的类型，第二个参数是ViewName（可省略，则默认为View类型的类名）
            //containerRegistry.RegisterForNavigation(typeof(ChartTest), "ChartTest");
            //注册为单例
            //containerRegistry.RegisterSingleton<ShowModel>();
            //containerRegistry.RegisterForNavigation<ShowModel>();
            //注册弹窗Dialog
            containerRegistry.RegisterDialog<DialogTest>();

        }
        //【3】注册自定义的RegionAdapter，使得其他控件类型也能装载prism页面
        protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
        {
            base.ConfigureRegionAdapterMappings(regionAdapterMappings);
            regionAdapterMappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
        }
        //【4】添加模块(先把子项目引用过来)
        //主项目中的region与子项目module中的视图关联已经在子项目定义过了
        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            base.ConfigureModuleCatalog(moduleCatalog);
            moduleCatalog.AddModule<ExcelModule.ExcelModule>();
            moduleCatalog.AddModule<PdfModule.PdfModule>();
        }
    }
}
